layui.use(['table','jquery','layer','form'],function () {
    table = layui.table;
    $ = layui.jquery;
    layer = layui.layer;
    form = layui.form;

    var orderTable = table.render({
        elem:"#root",
        url:'/returnComp/getAllReGoo',
        toolbar:'#toptool',
        defaultToolbar:['print','filter','exports'],
        page:true,
        limit:15,
        limits:[10,20,30],
        cols:[[
            {type:'checkbox',align:'center',width:60},
            {type:'orderId',title:'序号',align:'center',width:60,templet:function (data) {
                    return data.LAY_INDEX;
                }},
            {field:'nickname',title:'用户昵称',align:'center'},
            {field:'phone',title:'用户手机',align:'center'},
            {field:'orderSource',title:'订单来源',align:'center',templet:function (data) {
                    if (data.orderSource=="2"){
                        data.orderSource = "小程序";
                    }else if (data.orderSource=="3"){
                        data.orderSource = "app";
                    }
                    return "<p>"+data.orderSource+"</p>";
                }},
            {field:'orderStatus',title:'订单状态',align:'center',templet:function (data) {
                    if (data.orderStatus=="2"){
                        data.orderStatus = "未付款";
                    }else if (data.orderStatus=="3"){
                        data.orderStatus = "已付款";
                    }else if(data.orderStatus=="4"){
                        data.orderStatus = "待发货";
                    }else if(data.orderStatus=="5"){
                        data.orderStatus = "已发货";
                    }else if(data.orderStatus=="6"){
                        data.orderStatus = "已签收";
                    }else if(data.orderStatus=="7"){
                        data.orderStatus = "退货申请";
                    }else if(data.orderStatus=="11"){
                        data.orderStatus = "退货中";
                    }else if(data.orderStatus=="9"){
                        data.orderStatus = "已退货";
                    }else if(data.orderStatus=="10"){
                        data.orderStatus = "拒绝退订";
                    }
                    return "<p>"+data.orderStatus+"</p>";
                }},
            {field:'productName',title:'商品名称',align:'center'},
            {field:'productDescription',title:'商品描述',align:'center'},
            {field:'orderPaymentChannel',title:'支付渠道',align:'center',templet:function(data){
                    if (data.orderPaymentChannel == "2"){
                        data.orderPaymentChannel = "微信支付";
                    }else if (data.orderPaymentChannel =="3"){
                        data.orderPaymentChannel = "余额支付";
                    }
                    return "<p>"+data.orderPaymentChannel+"</p>";
                }},
            {field:'trueName',title:'商家名称',align:'center'},
            {field:'comment',title:'是否评论',align:'center',templet:function(data){
                    if (data.comment == "2"){
                        data.comment = "待评论";
                    }else if (data.comment =="3"){
                        data.comment = "已评论";
                    }
                    return "<p>"+data.comment+"</p>";
                }},
            {title:'操作',align:'center',templet:function (data) {
                    var tem = '<a  href="javascript:getLogById('+data.productId+');" style="color:rgb(13,171,158)">查看</a>' +
                        '<a  href="javascript:removeLogById('+data.orderId+');" style="margin-left: 20px;color:rgb(13,171,158)">删除</a>';
                    return tem;
                }},
        ]]
    });

    /* 模糊查询 */
    form.on('submit(sub)',function (data) {
        orderTable.reload({
            url:'/returnComp/getAllReGoo?orderPaymentChannel='+data.field.orderPaymentChannel+'&orderSource='+data.field.orderSource
        });
        return false;
    });
    /* 重置 */
    form.on('submit(subs)',function (data) {
        orderTable.reload({
            url:'/returnComp/getAllReGoo'
        });
    });
    /* 刷新 */
    form.on('submit(Refresh)',function (data) {
        orderTable.reload({
            url:'/returnComp/getAllReGoo'
        });
    });
    /* 查看 */
    getLogById = function getLogById(productId) {
        $.ajax({
            url: "/goodsTable/getProduct",
            type: "post",
            dataType: "json",
            data: {"productId": productId},
            success: function (data) {
                devicesMsg(data);
            },
        })
    }

    function devicesMsg(data) {
        layer.open({
            type: 2,
            title: "详情",
            area: ['1000px', '700px'],
            maxmin: true,
            btn:['关闭'],
            shade: 0,
            offset: 't',
            content: "/goods/goods-see.html",
            success: function (layero, index) {
                var obj = layero.find('iframe').contents();
                obj.find("#productCode").val(data.data.productCode);
                obj.find("#productName").val(data.data.productName);
                obj.find("#currentpriceProduct").val(data.data.currentpriceProduct);
                obj.find("#title").val(data.data.title);
                if (data.data.productSate == 0) {
                    obj.find("#productSate").val("已删除");
                } else if (data.data.productSate == 1) {
                    obj.find("#productSate").val("上架");
                } else if (data.data.productSate == 2) {
                    obj.find("#productSate").val("下架");
                } else {
                    return "";
                }
                obj.find('#saleNum').val(data.data.saleNum);
                obj.find('#saleNum').val(data.data.saleNum);
                obj.find("#hits").val(data.data.hits);
                obj.find("#collectionNum").val(data.data.collectionNum);
                obj.find("#productDescription").val(data.data.productDescription);
                obj.find("#productLabel").val(data.data.productLabel);
                obj.find("#mainImage").attr('src',data.data.mainImage);
            }
        });
    }
    /*表格详情结束*/

    /* 删除 */
    removeLogById = function removeLogById(orderId){
        layer.confirm("确定删除？",{btn: ['确定', '取消'],title:"提示"}, function(){
            $.ajax({
                url:"/returnComp/delReGoo",
                type:"post",
                dataType:"json",
                data:{"orderId":orderId},
                success:function(data){
                    layer.msg("删除成功");
                    orderTable.reload();
                }
            })
        });
    };


    /*全部订单开始*/
    quanbu = function quanbu(){
        $("#quanbu").css('display','block');
        $("#inreturn").css('display','none');
        $("#rejectUnsubscribe").css('display','none');
        $("#Unsubscribed").css('display','none');
        orderTable.reload({
            url:'/returnComp/getAllReGoo'
        });
    }
    /*全部订单结束*/

    /*退货中开始*/
    inreturn = function inreturn(){
        $("#quanbu").css('display','none');
        $("#inreturn").css('display','block');
        $("#rejectUnsubscribe").css('display','none');
        $("#Unsubscribed").css('display','none');
        var orderTable = table.render({
            elem:"#root",
            url:'/inreturn/getAllReGoo',
            toolbar:'#toptool',
            defaultToolbar:['print','filter','exports'],
            page:true,
            limit:15,
            limits:[10,20,30],
            cols:[[
                {type:'checkbox',align:'center',width:60},
                {type:'orderId',title:'序号',align:'center',width:60,templet:function (data) {
                        return data.LAY_INDEX;
                    }},
                {field:'nickname',title:'用户昵称',align:'center'},
                {field:'phone',title:'用户手机',align:'center'},
                {field:'orderSource',title:'订单来源',align:'center',templet:function (data) {
                        if (data.orderSource=="2"){
                            data.orderSource = "小程序";
                        }else if (data.orderSource=="3"){
                            data.orderSource = "app";
                        }
                        return "<p>"+data.orderSource+"</p>";
                    }},
                {field:'orderStatus',title:'订单状态',align:'center',templet:function (data) {
                        if (data.orderStatus=="2"){
                            data.orderStatus = "未付款";
                        }else if (data.orderStatus=="3"){
                            data.orderStatus = "已付款";
                        }else if(data.orderStatus=="4"){
                            data.orderStatus = "待发货";
                        }else if(data.orderStatus=="5"){
                            data.orderStatus = "已发货";
                        }else if(data.orderStatus=="6"){
                            data.orderStatus = "已签收";
                        }else if(data.orderStatus=="7"){
                            data.orderStatus = "退货申请";
                        }else if(data.orderStatus=="11"){
                            data.orderStatus = "退货中";
                        }else if(data.orderStatus=="9"){
                            data.orderStatus = "已退货";
                        }else if(data.orderStatus=="10"){
                            data.orderStatus = "拒绝退订";
                        }
                        return "<p>"+data.orderStatus+"</p>";
                    }},
                {field:'productName',title:'商品名称',align:'center'},
                {field:'productDescription',title:'商品描述',align:'center'},
                {field:'orderPaymentChannel',title:'支付渠道',align:'center',templet:function(data){
                        if (data.orderPaymentChannel == "2"){
                            data.orderPaymentChannel = "微信支付";
                        }else if (data.orderPaymentChannel =="3"){
                            data.orderPaymentChannel = "余额支付";
                        }
                        return "<p>"+data.orderPaymentChannel+"</p>";
                    }},
                {field:'trueName',title:'商家名称',align:'center'},
                {field:'comment',title:'是否评论',align:'center',templet:function(data){
                        if (data.comment == "2"){
                            data.comment = "待评论";
                        }else if (data.comment =="3"){
                            data.comment = "已评论";
                        }
                        return "<p>"+data.comment+"</p>";
                    }},
                {title:'操作',align:'center',templet:function (data) {
                        var tem = '<a  href="javascript:getLogById('+data.productId+');" style="color:rgb(13,171,158)">查看</a>' +
                            '<a  href="javascript:removeLogById('+data.orderId+');" style="margin-left: 20px;color:rgb(13,171,158)">删除</a>';
                        return tem;
                    }},
            ]]
        });

        /* 模糊查询 */
        form.on('submit(sub)',function (data) {
            orderTable.reload({
                url:'/inreturn/getAllReGoo?orderPaymentChannel='+data.field.orderPaymentChannel+'&orderSource='+data.field.orderSource
            });
            return false;
        });
        /* 重置 */
        form.on('submit(subs)',function (data) {
            orderTable.reload({
                url:'/inreturn/getAllReGoo'
            });
        });
        /* 刷新 */
        form.on('submit(Refresh)',function (data) {
            orderTable.reload({
                url:'/inreturn/getAllReGoo'
            });
        });

        /* 查看 */
        getLogById = function getLogById(productId) {
            $.ajax({
                url: "/goodsTable/getProduct",
                type: "post",
                dataType: "json",
                data: {"productId": productId},
                success: function (data) {
                    devicesMsg(data);
                },
            })
        }

        function devicesMsg(data) {
            layer.open({
                type: 2,
                title: "详情",
                area: ['1000px', '700px'],
                maxmin: true,
                shade: 0,
                btn:['关闭'],
                offset: 't',
                content: "/goods/goods-see.html",
                success: function (layero, index) {
                    var obj = layero.find('iframe').contents();
                    obj.find("#productCode").val(data.data.productCode);
                    obj.find("#productName").val(data.data.productName);
                    obj.find("#currentpriceProduct").val(data.data.currentpriceProduct);
                    obj.find("#title").val(data.data.title);
                    if (data.data.productSate == 0) {
                        obj.find("#productSate").val("已删除");
                    } else if (data.data.productSate == 1) {
                        obj.find("#productSate").val("上架");
                    } else if (data.data.productSate == 2) {
                        obj.find("#productSate").val("下架");
                    } else {
                        return "";
                    }
                    obj.find('#saleNum').val(data.data.saleNum);
                    obj.find('#saleNum').val(data.data.saleNum);
                    obj.find("#hits").val(data.data.hits);
                    obj.find("#collectionNum").val(data.data.collectionNum);
                    obj.find("#productDescription").val(data.data.productDescription);
                    obj.find("#productLabel").val(data.data.productLabel);
                    obj.find("#mainImage").attr('src',data.data.mainImage);
                }
            });
        }
        /*表格详情结束*/

        /* 删除 */
        removeLogById = function removeLogById(orderId){
            layer.confirm("确定删除？",{btn: ['确定', '取消'],title:"提示"}, function(){
                $.ajax({
                    url:"/inreturn/delReGoo",
                    type:"post",
                    dataType:"json",
                    data:{"orderId":orderId},
                    success:function(data){
                        layer.msg("删除成功");
                        orderTable.reload();
                    }
                })
            });
        };

    }
    /*退货中结束*/

    /*拒绝退订开始*/
    rejectUnsubscribe = function rejectUnsubscribe(){
        $("#quanbu").css('display','none');
        $("#inreturn").css('display','none');
        $("#rejectUnsubscribe").css('display','block');
        $("#Unsubscribed").css('display','none');
        var orderTable = table.render({
            elem:"#root",
            url:'/returnRef/getAllReGoo',
            toolbar:'#toptool',
            defaultToolbar:['print','filter','exports'],
            page:true,
            limit:15,
            limits:[10,20,30],
            cols:[[
                {type:'checkbox',align:'center',width:60},
                {type:'orderId',title:'序号',align:'center',width:60,templet:function (data) {
                        return data.LAY_INDEX;
                    }},
                {field:'nickname',title:'用户昵称',align:'center'},
                {field:'phone',title:'用户手机',align:'center'},
                {field:'orderSource',title:'订单来源',align:'center',templet:function (data) {
                        if (data.orderSource=="2"){
                            data.orderSource = "小程序";
                        }else if (data.orderSource=="3"){
                            data.orderSource = "app";
                        }
                        return "<p>"+data.orderSource+"</p>";
                    }},
                {field:'orderStatus',title:'订单状态',align:'center',templet:function (data) {
                        if (data.orderStatus=="2"){
                            data.orderStatus = "未付款";
                        }else if (data.orderStatus=="3"){
                            data.orderStatus = "已付款";
                        }else if(data.orderStatus=="4"){
                            data.orderStatus = "待发货";
                        }else if(data.orderStatus=="5"){
                            data.orderStatus = "已发货";
                        }else if(data.orderStatus=="6"){
                            data.orderStatus = "已签收";
                        }else if(data.orderStatus=="7"){
                            data.orderStatus = "退货申请";
                        }else if(data.orderStatus=="11"){
                            data.orderStatus = "退货中";
                        }else if(data.orderStatus=="9"){
                            data.orderStatus = "已退货";
                        }else if(data.orderStatus=="10"){
                            data.orderStatus = "拒绝退订";
                        }
                        return "<p>"+data.orderStatus+"</p>";
                    }},
                {field:'productName',title:'商品名称',align:'center'},
                {field:'productDescription',title:'商品描述',align:'center'},
                {field:'orderPaymentChannel',title:'支付渠道',align:'center',templet:function(data){
                        if (data.orderPaymentChannel == "2"){
                            data.orderPaymentChannel = "微信支付";
                        }else if (data.orderPaymentChannel =="3"){
                            data.orderPaymentChannel = "余额支付";
                        }
                        return "<p>"+data.orderPaymentChannel+"</p>";
                    }},
                {field:'trueName',title:'商家名称',align:'center'},
                {field:'comment',title:'是否评论',align:'center',templet:function(data){
                        if (data.comment == "2"){
                            data.comment = "待评论";
                        }else if (data.comment =="3"){
                            data.comment = "已评论";
                        }
                        return "<p>"+data.comment+"</p>";
                    }},
                {title:'操作',align:'center',templet:function (data) {
                        var tem = '<a  href="javascript:getLogById('+data.productId+');" style="color:rgb(13,171,158)">查看</a>' +
                            '<a  href="javascript:removeLogById('+data.orderId+');" style="margin-left: 20px;color:rgb(13,171,158)">删除</a>';
                        return tem;
                    }},
            ]]
        });

        /* 模糊查询 */
        form.on('submit(sub)',function (data) {
            orderTable.reload({
                url:'/returnRef/getAllReGoo?orderPaymentChannel='+data.field.orderPaymentChannel+'&orderSource='+data.field.orderSource
            });
            return false;
        });
        /* 重置 */
        form.on('submit(subs)',function (data) {
            orderTable.reload({
                url:'/returnRef/getAllReGoo'
            });
        });
        /* 刷新 */
        form.on('submit(Refresh)',function (data) {
            orderTable.reload({
                url:'/returnRef/getAllReGoo'
            });
        });
        /* 查看 */
        getLogById = function getLogById(productId) {
            $.ajax({
                url: "/goodsTable/getProduct",
                type: "post",
                dataType: "json",
                data: {"productId": productId},
                success: function (data) {
                    devicesMsg(data);
                },
            })
        }

        function devicesMsg(data) {
            layer.open({
                type: 2,
                title: "详情",
                area: ['1000px', '700px'],
                maxmin: true,
                shade: 0,
                offset: 't',
                btn:['关闭'],
                content: "/goods/goods-see.html",
                success: function (layero, index) {
                    var obj = layero.find('iframe').contents();
                    obj.find("#productCode").val(data.data.productCode);
                    obj.find("#productName").val(data.data.productName);
                    obj.find("#currentpriceProduct").val(data.data.currentpriceProduct);
                    obj.find("#title").val(data.data.title);
                    if (data.data.productSate == 0) {
                        obj.find("#productSate").val("已删除");
                    } else if (data.data.productSate == 1) {
                        obj.find("#productSate").val("上架");
                    } else if (data.data.productSate == 2) {
                        obj.find("#productSate").val("下架");
                    } else {
                        return "";
                    }
                    obj.find('#saleNum').val(data.data.saleNum);
                    obj.find('#saleNum').val(data.data.saleNum);
                    obj.find("#hits").val(data.data.hits);
                    obj.find("#collectionNum").val(data.data.collectionNum);
                    obj.find("#productDescription").val(data.data.productDescription);
                    obj.find("#productLabel").val(data.data.productLabel);
                    obj.find("#mainImage").attr('src',data.data.mainImage);
                }
            });
        }
        /*表格详情结束*/

        /* 删除 */
        removeLogById = function removeLogById(orderId){
            layer.confirm("确定删除？",{btn: ['确定', '取消'],title:"提示"}, function(){
                $.ajax({
                    url:"/returnRef/delReGoo",
                    type:"post",
                    dataType:"json",
                    data:{"orderId":orderId},
                    success:function(data){
                        layer.msg("删除成功");
                        orderTable.reload();
                    }
                })
            });
        };
    }
    /*拒绝退订结束*/

    /*已退订开始*/
    Unsubscribed = function Unsubscribed(){
        $("#quanbu").css('display','none');
        $("#inreturn").css('display','none');
        $("#rejectUnsubscribe").css('display','none');
        $("#Unsubscribed").css('display','block');
        var orderTable = table.render({
            elem:"#root",
            url:'/unsub/getAllReGoo',
            toolbar:'#toptool',
            defaultToolbar:['print','filter','exports'],
            page:true,
            limit:15,
            limits:[10,20,30],
            cols:[[
                {type:'checkbox',align:'center',width:60},
                {type:'orderId',title:'序号',align:'center',width:60,templet:function (data) {
                        return data.LAY_INDEX;
                    }},
                {field:'nickname',title:'用户昵称',align:'center'},
                {field:'phone',title:'用户手机',align:'center'},
                {field:'orderSource',title:'订单来源',align:'center',templet:function (data) {
                        if (data.orderSource=="2"){
                            data.orderSource = "小程序";
                        }else if (data.orderSource=="3"){
                            data.orderSource = "app";
                        }
                        return "<p>"+data.orderSource+"</p>";
                    }},
                {field:'orderStatus',title:'订单状态',align:'center',templet:function (data) {
                        if (data.orderStatus=="2"){
                            data.orderStatus = "未付款";
                        }else if (data.orderStatus=="3"){
                            data.orderStatus = "已付款";
                        }else if(data.orderStatus=="4"){
                            data.orderStatus = "待发货";
                        }else if(data.orderStatus=="5"){
                            data.orderStatus = "已发货";
                        }else if(data.orderStatus=="6"){
                            data.orderStatus = "已签收";
                        }else if(data.orderStatus=="7"){
                            data.orderStatus = "退货申请";
                        }else if(data.orderStatus=="11"){
                            data.orderStatus = "退货中";
                        }else if(data.orderStatus=="9"){
                            data.orderStatus = "已退货";
                        }else if(data.orderStatus=="10"){
                            data.orderStatus = "拒绝退订";
                        }
                        return "<p>"+data.orderStatus+"</p>";
                    }},
                {field:'productName',title:'商品名称',align:'center'},
                {field:'productDescription',title:'商品描述',align:'center'},
                {field:'orderPaymentChannel',title:'支付渠道',align:'center',templet:function(data){
                        if (data.orderPaymentChannel == "2"){
                            data.orderPaymentChannel = "微信支付";
                        }else if (data.orderPaymentChannel =="3"){
                            data.orderPaymentChannel = "余额支付";
                        }
                        return "<p>"+data.orderPaymentChannel+"</p>";
                    }},
                {field:'trueName',title:'商家名称',align:'center'},
                {field:'comment',title:'是否评论',align:'center',templet:function(data){
                        if (data.comment == "2"){
                            data.comment = "待评论";
                        }else if (data.comment =="3"){
                            data.comment = "已评论";
                        }
                        return "<p>"+data.comment+"</p>";
                    }},
                {title:'操作',align:'center',templet:function (data) {
                        var tem = '<a  href="javascript:getLogById('+data.productId+');" style="color:rgb(13,171,158)">查看</a>' +
                            '<a  href="javascript:removeLogById('+data.orderId+');" style="margin-left: 20px;color:rgb(13,171,158)">删除</a>';
                        return tem;
                    }},
            ]]
        });

        /* 模糊查询 */
        form.on('submit(sub)',function (data) {
            orderTable.reload({
                url:'/unsub/getAllReGoo?orderPaymentChannel='+data.field.orderPaymentChannel+'&orderSource='+data.field.orderSource
            });
            return false;
        });
        /* 重置 */
        form.on('submit(subs)',function (data) {
            orderTable.reload({
                url:'/unsub/getAllReGoo'
            });
        });
        /* 刷新 */
        form.on('submit(Refresh)',function (data) {
            orderTable.reload({
                url:'/unsub/getAllReGoo'
            });
        });
        /* 查看 */
        getLogById = function getLogById(productId) {
            $.ajax({
                url: "/goodsTable/getProduct",
                type: "post",
                dataType: "json",
                data: {"productId": productId},
                success: function (data) {
                    devicesMsg(data);
                },
            })
        }

        function devicesMsg(data) {
            layer.open({
                type: 2,
                title: "详情",
                area: ['1000px', '700px'],
                maxmin: true,
                shade: 0,
                offset: 't',
                btn:['关闭'],
                content: "/goods/goods-see.html",
                success: function (layero, index) {
                    var obj = layero.find('iframe').contents();
                    obj.find("#productCode").val(data.data.productCode);
                    obj.find("#productName").val(data.data.productName);
                    obj.find("#currentpriceProduct").val(data.data.currentpriceProduct);
                    obj.find("#title").val(data.data.title);
                    if (data.data.productSate == 0) {
                        obj.find("#productSate").val("已删除");
                    } else if (data.data.productSate == 1) {
                        obj.find("#productSate").val("上架");
                    } else if (data.data.productSate == 2) {
                        obj.find("#productSate").val("下架");
                    } else {
                        return "";
                    }
                    obj.find('#saleNum').val(data.data.saleNum);
                    obj.find('#saleNum').val(data.data.saleNum);
                    obj.find("#hits").val(data.data.hits);
                    obj.find("#collectionNum").val(data.data.collectionNum);
                    obj.find("#productDescription").val(data.data.productDescription);
                    obj.find("#productLabel").val(data.data.productLabel);
                    obj.find("#mainImage").attr('src',data.data.mainImage);
                }
            });
        }
        /*表格详情结束*/

        /* 删除 */
        removeLogById = function removeLogById(orderId){
            layer.confirm("确定删除？",{btn: ['确定', '取消'],title:"提示"}, function(){
                $.ajax({
                    url:"/unsub/delReGoo",
                    type:"post",
                    dataType:"json",
                    data:{"orderId":orderId},
                    success:function(data){
                        layer.msg("删除成功");
                        orderTable.reload();
                    }
                })
            });
        };
    }
    /*已退订结束*/

    $("#b1").click(function () {
        yes('b1');
        no('b2');
        no('b3');
        no('b4');

    });
    $("#b2").click(function () {
        no('b1');
        yes('b2');
        no('b3');
        no('b4');

    });
    $("#b3").click(function () {
        no('b1');
        no('b2');
        yes('b3');
        no('b4');

    });
    $("#b4").click(function () {
        no('b1');
        no('b2');
        no('b3');
        yes('b4');

    });

    function no(id) {
        var box = document.getElementById(id);
        box.style.backgroundColor='#F5F7F9';
        box.style.color='#666666';
        box.style.border="1px solid #D2D2D2";
    }
    function yes(id) {
        var box = document.getElementById(id);
        box.style.backgroundColor='#009688';
        box.style.color='white';
        box.style.border="1px solid #D2D2D2";
    }

    Refresh = function Refresh() {
        location.reload();
    }

    //返回
    goBack = function goBack() {
        parent.$('#beforeHref').val($('.layui-elem-quote').children('span').eq(0).text());
        parent.before();
        return false;
    }
});
